/*
 * Copyright 2008 FBK (http://www.fbk.eu/)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.fbk.it.hlt.jlsi.data;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

import org.apache.log4j.Logger;

/**
 * Represent a textual document.
 * 
 * @author Claudio Giuliano
 * @version %I%, %G%
 * @since 1.0
 */
public class TextDocument implements Document {
	/**
	 * Define a static logger variable so that it references the Logger instance
	 * named <code>TextDocument</code>.
	 */
	static Logger logger = Logger.getLogger(TextDocument.class.getName());

	/**
	 * The title of this document.
	 */
	private String title;

	/**
	 * The text of this document.
	 */
	private String text;

	/**
	 * The identifier of this document.
	 */
	private String id;

	/**
	 * Constructs a PubMed article.
	 */
	public TextDocument(File f) throws IOException {
		logger.debug("reading " + f);
		StringBuffer sb = new StringBuffer();
		BufferedReader in = new BufferedReader(new FileReader(f));

		int ch;
		while ((ch = in.read()) != -1) {
			// System.out.println((char) ch + " " + ch);
			sb.append((char) ch);
		} // end while

		title = "";
		text = sb.toString();
		id = f.getAbsolutePath();
		in.close();
	} // end constructor

	//
	public String title() {
		return title;
	} // end title

	//
	public String text() {
		return text;
	} // end text

	//
	public String id() {
		return id;
	} // end id

} // end class TextDocument